import sys

f = open(sys.argv[1])
for line in f:
    line = line.strip()
    parts = line.split()
    parents = parts[1].split(".")
    word_ids = parts[2].split(";")
    if len(parents) < 4:
        while len(parents) != 4:
            parents.append('-1')
    sql = "insert into item(id,p1,p2,p3,p4) values(%s,%s,%s,%s,%s);" % (parts[0],parents[0],parents[1],parents[2],parents[3])
    print sql
    for word_id in word_ids:
        sql = "insert into item_keyword(id,word_id) values(%s,%s);" % (parts[0],word_id)
        print sql
    
